/*
 * Copyright 2014 Jonathan Haas
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package app.grinreader.render;

import android.text.TextPaint;
import app.grinreader.model.BookPosition;
import app.grinreader.model.Element;
import app.grinreader.model.TextElement;

/**
 *
 */
public class TextLine {
	private final BookPosition startPosition;
	private final BookPosition endPosition;
	private final Element[] text;
	private final float indenting;
	private final float height;
	private float extraContentWidth;
	private float basicContentWidth;
	private float marginTop;
	private float marginBottom;
	private final TextPaint textPaint;
	private boolean pageBreak;

	public TextLine(BookPosition startPosition, BookPosition endPosition, Element[] text, float indenting, float height, float extraContentWidth, float basicContentWidth, TextPaint textPaint) {
		this.startPosition = startPosition;
		this.endPosition = endPosition;
		this.text = text;
		this.indenting = indenting;
		this.height = height;
		this.extraContentWidth = extraContentWidth;
		this.basicContentWidth = basicContentWidth;
		this.textPaint = textPaint;
	}

	public BookPosition getStartPosition() {
		return startPosition;
	}

	public BookPosition getEndPosition() {
		return endPosition;
	}

	public Element[] getText() {
		return text;
	}

	public float getIndenting() {
		return indenting;
	}

	public float getHeight() {
		return height;
	}

	public TextPaint getTextPaint() {
		return textPaint;
	}

	public float getExtraContentWidth() {
		return extraContentWidth;
	}

	public void setExtraContentWidth(float extraContentWidth) {
		this.extraContentWidth = extraContentWidth;
	}

	public float getBasicContentWidth() {
		return basicContentWidth;
	}

	public float getMarginTop() {
		return marginTop;
	}

	public void setMarginTop(float marginTop) {
		this.marginTop = marginTop;
	}

	public float getMarginBottom() {
		return marginBottom;
	}

	public void setMarginBottom(float marginBottom) {
		this.marginBottom = marginBottom;
	}

	public boolean isPageBreak() {
		return pageBreak;
	}

	public void setPageBreak(boolean pageBreak) {
		this.pageBreak = pageBreak;
	}

	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		for (Element textBlockElement : text) {
			if (textBlockElement instanceof TextElement) {
				TextElement textElement = (TextElement) textBlockElement;
				stringBuilder.append(textElement);
			}
		}
		return stringBuilder.toString();
	}
}
